﻿/*----------------------------------------------------------------
// Copyright (C) 2005 麦迪斯顿(北京)医疗科技发展有限公司
// 文件名：Identity.cs
// 文件功能描述：Identity
// 创建标识：顾伟伟-2012-04-14
----------------------------------------------------------------*/
using System;
using System.Collections.Generic;
using System.Text;

namespace Medicalsystem.Docare.Common.Principal
{
    [Serializable]
    /// <summary>
    /// 获取当前用户的标识
    /// </summary>
    public  class Identity
    {
        private List<string> _roles = new List<string>();
        private List<string> _actions = new List<string>();
        /// <summary>
        /// 当前用户的显示名称 USER_NAME
        /// </summary>
        public string UserName { get; set; }
        /// <summary>
        /// 该用户在MED_USER表中的USER_ID
        /// </summary>
        public string UserId { get; set; }
        /// <summary>
        /// 当前用户的登陆名称
        /// </summary>
        public string LoginName { get; set; }
        /// <summary>
        /// 该值指示是否验证了用户
        /// </summary>
        public bool IsAuthenticated { get; set; }
        /// <summary>
        /// 登陆科室代码
        /// </summary>
        public string OfficeId { get; set; }
        /// <summary>
        /// 登陆科室名称
        /// </summary>
        public string OfficeName { get; set; }
        /// <summary>
        /// 是否是超级用户
        /// 超级用户指：实施工程师，系统管理员
        /// </summary>
        public bool IsSuperUser
        {
            get
            {
                return this.AuthenticationType == AuthenticationType.Medicalsystemer
                    || this.AuthenticationType == AuthenticationType.Administrator;
            }
        }
        /// <summary>
        /// 用户的身份验证类型
        /// </summary>
        public AuthenticationType AuthenticationType { get; set; }
        /// <summary>
        /// 登陆用户的权限列表
        /// </summary>
        public List<string> Permissions
        {
            get
            {
                return _actions;
            }
        }
        /// <summary>
        /// 登陆用户的角色
        /// </summary>
        public List<string> Roles
        {
            get
            {
                return _roles;
            }
        }
        /// <summary>
        /// 获取用户在MED_HIS_USER表中的数据
        /// </summary>
        public HisUserInfo HisInfo { get; set; }
       
        /// <summary>
        ///判断用户是否具备permissionId标识的权限
        /// </summary>
        /// <param name="actionName">permissionId</param>
        /// <returns></returns>
        public bool IsAuthorized(string permissionId)
        {
            if (this.IsSuperUser)
                return true;

            return this._actions.Contains(permissionId);
        }
        /// <summary>
        /// 用户是否在处于roleId标识的角色中
        /// </summary>
        /// <param name="roleId"></param>
        /// <returns></returns>
        public bool IsInRole(string roleId)
        {
            if (this.IsSuperUser)
                return true;

            return this._roles.Contains(roleId);
        }
    }
    /// <summary>
    /// 获取登陆用户在MED_HIS_USER表中的数据
    /// </summary>
    [Serializable]
    public class HisUserInfo
    {
        /// <summary>
        /// 用户ID
        /// </summary>
        public string UserId { get; set; }

        /// <summary>
        /// 用户名称
        /// </summary>
        public string UserName { get; set; }

        /// <summary>
        /// 科室ID
        /// </summary>
        public string OfficeId { get; set; }

        /// <summary>
        /// 科室名称
        /// </summary>
        public string OfficeName { get; set; }

        /// <summary>
        /// 用户的职称
        /// </summary>
        public string Career { get; set; }
    }
}
